﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MantisCommon
{
    public partial class BugSelection : Form, Common.Forms.IBugSelection
    {
        private MyBugtracker m_mcm = null;

        public BugSelection(String parameters)
        {
            InitializeComponent();
            m_mcm = new MyBugtracker(new Settings.MySettingsManager(parameters));
        }

        public String BugId
        {
            get { return dataGridView1.SelectedRows[0].Cells["cIssueID"].Value.ToString(); }
        }

        public String Message
        {
            get { return "-----\r\nBugID : " + BugId + " (" + (radioButton1.Checked ? radioButton1.Text : radioButton2.Text) + ")\r\n\r\n" + dataGridView1.SelectedRows[0].Cells["cIssueSummary"].Value.ToString(); }
        }

        private void BugSelection_Load(object sender, EventArgs e)
        {
            dsData.dtIssueData.Merge(m_mcm.GetIssuesList());
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
                btnOk.Enabled = true;
        }

        public bool AddCheckIn(string source_base_path, string note, string revision, string[] filelist)
        {
            if (!string.IsNullOrEmpty(source_base_path))
            {
                note += string.Format("{0} - ", source_base_path);
            }

            note += string.Format("Revision : {0}{1}", revision, Environment.NewLine);

            if (filelist.Length > 0)
            {
                note += " -----Files list----- ";

                foreach (string s in filelist)
                    note += Environment.NewLine + s;
            }

            return m_mcm.IssueCheckinAdd(BugId, note, radioButton1.Checked);
        }
    }
}
